Imports Microsoft.VisualBasic
Imports System.Net

Friend Class SendMailObject_CDOCredentials
    Inherits SendMailObject_CDO

    Protected msUserID As String
    Protected msPassword As String

    Public Sub New( _
                ByVal sEmailServer As String, _
                ByVal sUserID As String, _
                ByVal sPassword As String)

        MyBase.New(sEmailServer)

        msUserID = sUserID
        msPassword = sPassword
    End Sub

    Public Overrides Function SendMessage( _
            ByVal oMessage As Message) As String

        Dim sResult As String = ""

        Try
            Dim oSMTPMessage As Mail.MailMessage = ComposeSMTPMessage(oMessage)
            Dim oSMTPServer As New System.Net.Mail.SmtpClient(msEmailServer, 25)

            oSMTPServer.Credentials = New NetworkCredential(msUserID, msPassword)
            oSMTPServer.DeliveryMethod = Mail.SmtpDeliveryMethod.Network
            oSMTPServer.Send(oSMTPMessage)

        Catch ex As Exception
            sResult = ex.Message
        End Try

        Return sResult
    End Function
End Class